package student.action;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.util.DB;
import com.util.MyLog;

import edu.student.models.*;

/**
Author: Satya Deepthi Bhagi
**/

public class DisplayProfile extends ActionSupport{

	private String friendName;
	private ArrayList<Interest> interests;
   User friend =new User();
   private String username="";
	private List<News> news;
	private List<Announcements> announcements;
	private String image="";
	private Timestamp lastLogin;
	private String userid="";
	
	

   public String getUserid() {
		return userid;
	}

	public void setUserid(String userid) {
		this.userid = userid;
	}

	public List<Announcements> getAnnouncements() {
	 		return announcements;
	 	}

	 	public void setAnnouncements(List<Announcements> announcements) {
	 		this.announcements = announcements;
	 	}

	 	public List<News> getNews() {
	 		return news;
	 	}

	 	public void setNews(List<News> news) {
	 		this.news = news;
	 	}
	 	public String getUsername() {
	 		return username;
	 	}

	 	public void setUsername(String username) {
	 		this.username = username;
	 	}
	 	

	 	public String getImage() {
	 		return image;
	 	}

	 	public void setImage(String image) {
	 		this.image = image;
	 	}
	 	public Timestamp getLastLogin() {
	 		return lastLogin;
	 	}

	 	public void setLastLogin(Timestamp lastLogin) {
	 		this.lastLogin = lastLogin;
	 	}

   
	public String execute() throws Exception {
		Map<String, Object> session = ActionContext.getContext().getSession();
		User user = (User) session.get("user");
		if (user == null) {
			user = new User();
		}		
		userid=user.getRollNor();
		username=user.getUsername();
		image=user.getImage();
		lastLogin=user.getLastLogin();
		news = News.getNews(" where ui.roll_No='"+userid+"' ");
		announcements=Announcements.getAnnouncements(" where ui.roll_No='"+userid+"' ");
		MyLog.log("\nFriend Name getting from jsp is"+friendName);
		friend = User.findone("select * from user where user_name= '" + friendName+"'");
		friend.setInterests(Interest.getInterests(" where u.user_name='"+friendName+"' "));
		return "success";
	}
	
	public String getFriendName() {
		return friendName;
	}

	public void setFriendName(String friendName) {
		this.friendName = friendName;
	}

	
	public ArrayList<Interest> getInterests() {
		return interests;
	}

	public void setInterests(ArrayList<Interest> interests) {
		this.interests = interests;
	}

	public User getFriend() {
		return friend;
	}

	public void setFriend(User friend) {
		this.friend = friend;
	}

	
	
}
